<script setup>
import tableList from "@/components/tableList/tableList.vue";
import {logList} from "@/api/system/log";
import {useCommon} from "@/hooks/web/useCommon";

const {
  pageData,
  teacherOptions,
  getTeacher
} = useCommon()
const router = useRouter()
onBeforeMount(() => {
  getTeacher('')
  fetchData()
})

let tableData = reactive([])
let loading = ref(false)

const tableHeader = reactive([
  {label: '操作API接口', prop: 'url'},
  {label: '操作备注', prop: 'remark'},
  {label: '操作人', prop: 'realname'},
  {label: '操作时间', prop: 'created_time'}
])

let searchRef = ref('')
const handleReset = () => {
  searchRef.value.resetFields()
}
const onSearch = (type) => {
  pageData.currentPage = 1
  fetchData();
}

const searchForm = reactive({
  uid: '',
  time: '',
})
const fetchData = async () => {
  let params = searchForm
  params.page = pageData.currentPage
  params.limit = pageData.pageSize
  loading.value = true
  let res = await logList(params)
  loading.value = false
  if (res) {
    tableData.splice(0)
    tableData.push(...res.data.list)
    pageData.total = res.data.page.amount
  }
}

const handlePageChange = (param) => {
  pageData.pageSize = param.limit
  pageData.currentPage = param.page
  fetchData()
}


</script>
<template>
  <el-row>
    <el-col :span="24">
      <el-form :inline="true" :model="searchForm" class="el-input-form" ref="searchRef">
        <el-form-item label="操作人" prop="uid">
          <el-select v-model="searchForm.uid" placeholder="请选择操作人" clearable>
            <el-option v-for="(item, index) in teacherOptions" :label="item.name" :value="item.id"
                       :key="index">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="操作时间" prop="time">
          <el-date-picker
              style="width:100%;"
              clearable
              v-model="searchForm.time"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              type="date"
              placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="onSearch" clearable icon="search">查询</el-button>
          <el-button @click="handleReset" icon="RefreshLeft">重置</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="24" v-loading="loading" class="table-wrap">
      <tableList :table-data="tableData"
                 :page-data="pageData"
                 :table-header="tableHeader"
                 @handle-page-change="handlePageChange"
      ></tableList>
    </el-col>
  </el-row>
</template>


